<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>HashRouter 的原理</title>
    <style>
        #result{
            height: 300px;
            width: 400px;
            border:solid 1px #666;
        }
    </style>
</head>
<body>
    <a href="#home">Home</a>
    <a href="#about">About</a>
    <hr>
    <div id="result">

    </div>

    <script>
        let result = document.querySelector('#result');
        // hashChange   hash 锚点  change改变
        window.addEventListener('hashchange', function(){
            //获取当前网页的 hash 值    location 获取当前网页 URL 的相关讯息 协议 域名 端口  路径 查询字符串  『锚点』
            // console.log(location);
            //判断
            switch(location.hash){
                case '#home':
                    //修改 result 元素的内容
                    result.innerHTML = 'HOME HOME HOME';
                    break;
                case '#about':
                    result.innerHTML = 'ABOUT ABOUT ABOUT';
                    break;
                
                default:
                    result.innerHTML = '404 Not Found';
            }
        })
    </script>
</body>
</html>